package com.coderman.basketball.app.executor;

import com.coderman.basketball.app.command.trade.TradeTeamApplyCommand;
import com.coderman.basketball.domain.gataway.trade.TradeRepository;
import com.coderman.basketball.domain.model.trade.event.TradeApplyResultEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Description:
 * date: 2021/5/25
 *
 * @author shenshuai
 * @version 1.0.0
 * @since JDK 1.8
 */
@Service
public class TradeTeamApplyExecutor {
    @Autowired
    private TradeRepository tradeRepository;

    /**
     * 执行发起交易申请命令
     * @param tradeTeamApplyCommand
     */
    public void exeCommand(TradeTeamApplyCommand tradeTeamApplyCommand){

    }

    /**
     * 执行消息消费逻辑+事务
     * @param tradeApplyResultEvent
     */
    @Transactional(rollbackFor = Exception.class)
    public void exeTradeApplyResultEvent(TradeApplyResultEvent tradeApplyResultEvent){
        //交易申请被联盟同意

        if(tradeApplyResultEvent.getCheckResult().equals("success")){
            //1.执行交易申请成功后的逻辑
            tradeRepository.tradeSuccess(tradeApplyResultEvent.getTradeApplyCode());
            //2.由于存在交易中的薪资问题，这里会根据业务规则进行调整，比如交易中会产生交易特例来达到薪资配平的场景
            //3.交易成功之后可以进行下一步业务通知，比如发消息给球员和球队经理。


            // //1.修改交易申请单状态  按业务情况将以下逻辑在本服务中串联
            //        //2.修改当前合同执行球队
            //        //3.增加球员 球队关联关系
            //        //4.修改球队选秀权所属球队
            //        //5.增加球队资产--交易中体现现金
            //        //5.根据交易规则可能产生一定特定条件下的特例
        }else {
            tradeRepository.tradeFail(tradeApplyResultEvent.getTradeApplyCode());
        }
    }

}
